The PIC 16F88 chip has 13 pins which can be connected to the outside world. Other PICmicros have more or less pins, but the general philosophy is the same. Each of the pins can be either an input (we can use it to sense a voltage which may be applied to it) or an output (we can use it to produce a voltage).
At the moment we are considering purely digital behaviour, in that the signals will be either on or off. Other PIC microcontrollers have components which let them measure voltage levels and convert them to numbers (Analogue to Digital Converters). The PIC microcontroller provides locations in the Special Function Register area which are used to interact with these pins. Such locations are called ports.
The 13 Programmable Input/Output (PIO) pins on the PIC16F88 are provided in two ports. Port A has 5 bits and Port B has eight bits.
The two tables on the right show the arrangement of the ports. Each pin is mapped onto a single bit in a given port. Because of the way that binary numbers are stored we can say that putting a particular power of two into a port will set one of the bits. For example, putting the value 2 into Port B will set the bit RB1 (note that we number pins starting at 0). If that bit was configured as an output it would mean that we are setting pin 7 on the PIC microcontroller into the high state.
We can set several pins high at the same time by adding our powers of two together. For example to set RA3 and RA4 high we would use:
8 (the value for RA3) plus 16 (the value for RA4) - giving a value of 24 for Port A.
This would set pins 3 and 2 high. We will have to get used to combining powers of two in this way, we will also use these tricks to set the data direction registers. Note that we can control the state of the bits in a register by loading an eight bit value (which would update all the pins at once) or by setting or clearing individual pins. We will look at how this is done a little later.
Port A |
Bit 7 |
Bit 6 |
Bit 5 |
Bit 4 |
Bit 3 |
Bit 2 |
Bit 1 |
Bit 0 |
Power of 2 |
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
HEX value |
0x80 |
0x40 |
0x20 |
0x10 |
0x08 |
0x04 |
0x02 |
0x01 |
|
N/C |
N/C |
N/C |
PIN 3 |
PIN 2 |
PIN 1 |
PIN 18 |
PIN 17 |
Port B |
Bit 7 |
Bit 6 |
Bit 5 |
Bit 4 |
Bit 3 |
Bit 2 |
Bit 1 |
Bit 0 |
Power of 2 |
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
HEX value |
0x80 |
0x40 |
0x20 |
0x10 |
0x08 |
0x04 |
0x02 |
0z01 |
|
PIN 13 |
PIN 12 |
PIN 11 |
PIN 10 |
PIN 9 |
PIN 8 |
PIN 7 |
PIN 6 |